<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
</head>
<style>
    .layui-checkbox-disbaled[lay-skin=primary] span {
        color: rgba(99, 99, 99, 0.89);
    }

    #ly-form .layui-form .layui-form-label {
        width: 70px !important;
    }

    #remark-input {
        min-width: 350px !important;
    }

    .layui-table-click {
        background-color: #add3c2 !important;
    }
</style>
<body>
<div class="layui-col-md12" id="operatorInfo">
    <div class="layui-card" id="ly-form">
        <div class="layui-card-header">操作员信息</div>
        <div class="layui-card-body">
            <form class="layui-form" action="">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">用户名</label>
                        <div class="layui-input-inline">
                            <input type="tel" name="username" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">密码</label>
                        <div class="layui-input-inline">
                            <input type="password" name="password" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">备注</label>
                        <div class="layui-input-inline">
                            <input type="text" name="remark" id="remark-input" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item" pane="">
                    <label class="layui-form-label"></label>
                    <div class="layui-input-block">
                        <input type="checkbox" name="system[1]" lay-skin="primary" title="实时监控">
                        <input type="checkbox" name="system[2]" lay-skin="primary" title="视频预览" checked="">
                        <input type="checkbox" name="system[3]" lay-skin="primary" title="数据监控">
                    </div>
                </div>
                <div class="layui-form-item" pane="">
                    <label class="layui-form-label"></label>
                    <div class="layui-input-block">
                        <input type="checkbox" name="system[1]" lay-skin="primary" title="系统参数" checked="">
                        <input type="checkbox" name="system[2]" lay-skin="primary" title="基本参数" checked="">
                        <input type="checkbox" name="system[3]" lay-skin="primary" title="数据库">
                        <input type="checkbox" name="system[3]" lay-skin="primary" title="服务器设置">
                    </div>
                </div>
                <div class="layui-form-item" pane="">
                    <label class="layui-form-label"></label>
                    <div class="layui-input-block">
                        <input type="checkbox" name="system[1]" lay-skin="primary" title="企业管理">
                        <input type="checkbox" name="system[2]" lay-skin="primary" title="企业信息" checked="">
                        <input type="checkbox" name="system[3]" lay-skin="primary" title="部门信息">
                        <input type="checkbox" name="system[3]" lay-skin="primary" title="系统操作员" checked="">
                    </div>
                </div>
                <div class="layui-form-item" pane="">
                    <label class="layui-form-label"></label>
                    <div class="layui-input-block">
                        <input type="checkbox" name="system[1]" lay-skin="primary" title="人员管理" checked="">
                        <input type="checkbox" name="system[2]" lay-skin="primary" title="添加人员">
                        <input type="checkbox" name="system[3]" lay-skin="primary" title="人事管理" checked="">
                        <input type="checkbox" name="system[3]" lay-skin="primary" title="人员授权">
                        <input type="checkbox" name="system[3]" lay-skin="primary" title="人员同步">
                        <input type="checkbox" name="system[3]" lay-skin="primary" title="设备名单">
                    </div>
                </div>
                <div class="layui-form-item" pane="">
                    <label class="layui-form-label"></label>
                    <div class="layui-input-block">
                        <input type="checkbox" name="system[1]" lay-skin="primary" title="数据查询">
                        <input type="checkbox" name="system[2]" lay-skin="primary" title="考勤数据" checked="">
                        <input type="checkbox" name="system[3]" lay-skin="primary" title="人脸记录">
                        <input type="checkbox" name="system[3]" lay-skin="primary" title="刷卡记录">
                    </div>
                </div>
                <div class="layui-form-item" pane="">
                    <label class="layui-form-label"></label>
                    <div class="layui-input-block">
                        <input type="checkbox" name="system[1]" lay-skin="primary" title="设备管理">
                        <input type="checkbox" name="system[2]" lay-skin="primary" title="搜索设备">
                        <input type="checkbox" name="system[3]" lay-skin="primary" title="添加设备">
                        <input type="checkbox" name="system[3]" lay-skin="primary" title="摄像机管理" checked="">
                        <input type="checkbox" name="system[3]" lay-skin="primary" title="控制板管理">
                    </div>
                </div>
                <div class="layui-form-item" id="editBtn">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="updateBtn">确认修改</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<script src="/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table'], function () {
        let $ = layui.jquery,
            form = layui.form,
            table = layui.table;

        table.render({
            elem: '#operatorUser',
            url: '/api/operator.json',
            toolbar: '#toolbar',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [
                [
                    {field: 'id', width: 80, title: '序号', sort: true},
                    {field: 'username', width: 100, title: '用户名'},
                    {field: 'remark', width: 880, title: '备注', sort: true},
                    {title: '操作', minWidth: 50, toolbar: '#currentTableBar', fixed: "right", align: "center"}

                ]
            ],
            limits: [5, 10],
            limit: 5,
            page: true
        });


        //监听行单击事件（）
        table.on('row(currentTableFilter)', function (obj) {
            let data = obj.data;
            //单行点击后显示操作员信息
            // showOperatorInfo();
            obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            let result = JSON.stringify(data.field);
            layer.alert(result, {
                title: '最终的搜索信息'
            });
            //执行搜索重载
            table.reload('operatorUser', {
                page: {
                    curr: 1
                }
                , where: {
                    searchParams: result
                }
            }, 'data');

            return false;
        });
        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                let index = layer.open({
                    title: '添加用户',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/admin/enterprise/add',
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            }
        });
        //监听修改提交
        form.on('submit(updateBtn)', function (data) {
            $.post("face/updateBtn", {
                data: data
            }, function (data) {
                let iframeIndex = parent.layer.getFrameIndex(window.name);
                parent.layer.close(iframeIndex);

            });

            return false;
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });

        table.on('tool(currentTableFilter)', function (obj) {
            let data = obj.data;
            //console.log(data.id);
            if (obj.event === 'edit') {
                let index = layer.open({
                    title: '编辑用户',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '/admin/enterprise/add?id='+data.id+'' //传值过去，通过id查值修改
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'delete') {
                layer.confirm('真的删除行么', function (index) {
                    obj.del();
                    layer.close(index);
                });
            }
        });

    });
</script>
<script>
</script>
</body>
</html>